package org.ohuang

import java.io.File

/**
 * 在path 路径下寻找名字叫 fileName的文件
 */
fun searchFileInPath(path: String, fileName: Array<String>, data: MutableList<String>) {
    var file = File(path)
    file.listFiles()?.forEach { f0 ->
        if (f0.isDirectory) {
            fileName.forEach { fn ->
                if (fn == f0.name) {
                    data.add(f0.absolutePath)
                }
            }

            searchFileInPath(f0.absolutePath, fileName, data)
        } else {
            fileName.forEach { fn ->
                if (fn == f0.name) {
                    data.add(f0.absolutePath)
                }
            }
        }
    }
}

fun searchFileInPath(path: String, fileName: String, data: MutableList<String>) {
    var file = File(path)
    file.listFiles()?.forEach { f0 ->
        if (f0.isDirectory) {
            if (fileName == f0.name) {
                data.add(f0.absolutePath)
            }
            searchFileInPath(f0.absolutePath, fileName, data)
        } else {
            if (fileName == f0.name) {
                data.add(f0.absolutePath)
            }
        }
    }
}